<template>
  <div class="approval">
    <el-card class="box-card" style="margin-top: 110px;">
      <div class="head-title2">
          <div class='title'>
            {{$t('achievements.title1')}}
          </div>
          <div class="info">
            <el-tooltip placement="left">
              <div slot="content">
                {{define}}
              </div>
              <div class="btns"></div>
            </el-tooltip>
          </div>
        </div>
      <div class="menu-search">
        <!-- 时间 -->
        <div class="menu-title">
          <div class="searchItem">
            <span>{{$t('approvalDetail.riskTime')}}：</span>
            <el-date-picker
              v-model="listQuery.amountDateStr"
              type="month"
              size="small"
              value-format="yyyy-MM"
              :placeholder="$t('realTimeData.choiceDate')"
            ></el-date-picker>
          </div>
          <div class="menu-title-btn">
            <button type="button" @click="search">{{$t('btn.query')}}</button>
          </div>
        </div>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-top: 10px;margin-bottom: 20px;">
      <div class="title">{{$t('DailyStatistics.ListDetails')}}</div>
      <el-table
        v-loading="listLoading"
        ref="multipleTable"
        :data="financeList"
        tooltip-effect="dark"
        style="width: 100%"
        border
        stripe
        size="mini"
      >
        <!-- 日期 -->
        <el-table-column
          width="180"
          align="center"
          header-align="center"
          prop="amountDate"
          :label="$t('overdueData.time')"
        ></el-table-column>
        <!-- 实际放款金额 -->
        <el-table-column
          width="180"
          align="center"
          header-align="center"
          prop="lendAllAmt"
          :label="$t('FinanceReport.ActualLoanAmt')"
        ></el-table-column>
        <!-- 实际收款金额 -->
        <el-table-column
          width="180"
          align="center"
          header-align="center"
          prop="repayAllAmt"
          :label="$t('FinanceReport.ActualAmtReceipt')"
        ></el-table-column>
        <!-- 当月放款收回金额 -->
        <el-table-column
          width="180"
          align="center"
          header-align="center"
          prop="instantRepayAmt"
          :label="$t('FinanceReport.SameMonthAmtRecover')"
        ></el-table-column>
        <!-- 历史放款收回金额 -->
        <el-table-column
          width="180"
          align="center"
          header-align="center"
          prop="historicalRepayAmt"
          :label="$t('FinanceReport.HistoryAmtRecover')"
        ></el-table-column>
        <!-- 待收金额 -->
        <el-table-column
          width="180"
          align="center"
          header-align="center"
          prop="instantNotRepayAmt"
          :label="$t('FinanceReport.CollectAmt')"
        ></el-table-column>
        <!-- 当月逾期金额 -->
        <el-table-column
          width="180"
          align="center"
          header-align="center"
          prop="instantOverdueAmt"
          :label="$t('FinanceReport.SameMontOverdueAmt')"
        ></el-table-column>
        <!-- 历史逾期金额 -->
        <el-table-column
          width="180"
          align="center"
          header-align="center"
          prop="historicalOverdueAmt"
          :label="$t('FinanceReport.HistoryOverdueAmt')"
        ></el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.page"
          :page-sizes="[5, 10, 20, 30]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { formatAmt } from 'utils/index';
import { page } from "api/reportForm/FinanceReport/index";
export default {
  data() {
    return {
      define: '',
      listLoading: false,
      financeList: [],
      listQuery: {
        amountDateStr: "",
        page: 1,
        limit: 5,
      },
      total: null
    };
  },
  created() {
    if (this.financeReport.has(this.$route.path)) {
      this.listQuery = this.financeReport.get(this.$route.path);
    }
    this.getTime();
    this.getList();
    // 获取报表定义
    this.getReportDefine.forEach(item => {
      if (item.dictCode === 'FINANCIAL_STATEMENTS') {
        this.define = item.dictValue
      }
    })
  },
  computed: {
    ...mapGetters(["financeReport", 'getReportDefine'])
  },
  methods: {
    getTime() {
      let date = new Date();
      let seperator1 = "-";
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      this.listQuery.amountDateStr = year + seperator1 + month;
    },
    getList() {
      this.listLoading = true;
      this.$store.dispatch("saveFinanceReport", {
        path: this.$route.path,
        listQuery: this.listQuery
      });
      page(this.listQuery).then(response => {
        if (response.status === 200) {
          this.listLoading = false;
          if (this.isArray(response.data.rows) === true) {
            response.data.rows.forEach(item => {
              if (item.lendAllAmt || item.repayAllAmt || item.instantRepayAmt || item.historicalRepayAmt || item.instantNotRepayAmt || item.instantOverdueAmt || item.historicalOverdueAmt) {
                item.lendAllAmt = formatAmt(item.lendAllAmt);
                item.repayAllAmt = formatAmt(item.repayAllAmt);
                item.instantRepayAmt = formatAmt(item.instantRepayAmt);
                item.historicalRepayAmt = formatAmt(item.historicalRepayAmt);
                item.instantNotRepayAmt = formatAmt(item.instantNotRepayAmt);
                item.instantOverdueAmt = formatAmt(item.instantOverdueAmt);
                item.historicalOverdueAmt = formatAmt(item.historicalOverdueAmt);
              }
            })
            this.financeList = response.data.rows;
            this.total = Number(response.data.total);
          } else {
            this.financeList = [];
          }
        }
      });
    },
    isArray(obj) {
      return Object.prototype.toString.call(obj) === '[object Array]';
    },
    //查询
    search() {
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    }
  }
};
</script>

<style scoped lang='scss'>
.box-card {
  width: 95%;
  margin-left: 2.5%;
  margin-right: 2.5%;
}
.title {
  line-height: 30px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before {
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-title {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .searchItem {
    display: flex;
    align-items: center;
    padding: 10px 0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div {
      width: 150px;
    }
  }
  .searchItem-date {
    display: flex;
    align-items: center;
    padding: 10px 0;
    b {
      margin: 0 10px;
      font-weight: normal;
      font-size: 12px;
      color: #5f5f61;
    }
    div {
      width: 150px;
    }
  }
  .searchItem-overdue {
    display: flex;
    align-items: center;
    padding: 10px 0;
    div {
      width: 48px;
    }
  }
}
.menu-title-btn {
  margin-left: 20px;
  padding: 10px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
    &:nth-child(2) {
      background: #ebf5ff;
      color: #20a0ff;
      border: 1px solid #abd5ff;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.head-title2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btns {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-size: cover;
  background-image: url("../../../assets/images/question-mark.svg");
}
</style>